<%--
  Created by IntelliJ IDEA.
  User: teacher
  Date: 2022/4/14
  Time: 13:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户注册</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
    <script>
        $(function(){
           $("#username").blur(function(){
               // get 请求
              <%--$.get("${pageContext.request.contextPath}/checkUsername?username="+$(this).val(),--%>
                  <%--// 此处的参数相当于let result = xhr.responseText--%>
                  <%--function(result){--%>
                    <%--$("#s1").html(result);--%>
              <%--});--%>
              // post请求
               // 参数传递时,支持JSON语法
               $.post("${pageContext.request.contextPath}/checkUsername",
                   {"username":$(this).val()},
               function(result){
                   $("#s1").html(result);
               });
           });
        });
    </script>
</head>
<body>
<h1>用户注册</h1>
<hr/>
<form action="#" method="post">
    用户名:<input type="text" id="username"/><span id="s1"></span><br/>
    密&nbsp;&nbsp;&nbsp;码:<input type="password" name="password"/><br/>
    电&nbsp;&nbsp;&nbsp;话:<input type="text" name="phone"/><br/>
    地&nbsp;&nbsp;&nbsp;址:<input type="text" name="address"/><br/>
    <input type="submit" value="注册">
</form>
</body>
</html>
